//
//  MYGRegisterAPI.swift
//  MYGrow
//
//  Created by 小火科技 on 2024/3/11.
//

import UIKit
import Moya

enum MYGRegisterAPI {
    case getCode(phone: String)
    case login(phone: String, code: String)
    case change(patientId: Int)
    case addPatient(params: [String: Any])
    case add(content: String, type: Int, medias: [String] = [], address: String, lng: String, lat: String, range: Int)
    case uploadDoctorInf(id:String,params:[String:Any])//更新医生信息
}

extension MYGRegisterAPI: MYGTargetType {
    var params: [String : Any] {
        var params: [String: Any] = [:]
        switch self {
        case .getCode(let phone):
            params["phone"] = phone
        case let .login(phone, code):
            params["phone"] = phone
            params["code"] = code
        case let .change(patientId):
            params["patinet_id"] = patientId
        case let .addPatient(params):
            return params
        case let .add(content, type, medias, address, lng, lat, range):
            params["content"] = content
            params["type"] = type
            params["medias"] = medias
            params["address"] = address
            params["lng"] = lng
            params["lat"] = lat
            params["range"] = range
        case .uploadDoctorInf(id:let id,params: let params):
            return params
        }
        return params
    }
    
    var path: String {
        switch self {
        case .getCode:
            "/api/passport/send_sms"
        case .login:
            "/api/passport/login"
        case .change:
            "/api/patient/change_user_patient"
        case .addPatient:
            "/api/patient/add_patient"
        case .add:
            "/api/micro/posts"
        case .uploadDoctorInf(let id,let params):
            "/api/doctor/update/\(id)"
        }
    }
    
    var baseURL: URL {
        switch self {
        case .getCode,.login,.add,.uploadDoctorInf:
            return  URL(string: BaseUrl)!
        case .change,.addPatient:
            return  URL(string: Url)!
        }
    }
    var method: Moya.Method {
        switch self {
        case .getCode:
            .get
        case .login:
            .get
        case .change:
            .get
        case .addPatient:
            .get
        case .add:
            .post
        case .uploadDoctorInf:
            .put
        
        }
    }
}
